import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
import { HintsService } from '../../../public/serve/hints/hints.service';
import { template } from '../../product.data';
import { Service } from 'app/server/server';

@Component({
  selector: 'app-template-delete',
  templateUrl: './template-delete.component.html',
  styleUrls: ['./template-delete.component.css']
})
export class TemplateDeleteComponent implements OnInit {

  @Output() delete = new EventEmitter<void>();
  loading: boolean;
  constructor(
    public removeTableService: RemoveTableService,
    private hintsService: HintsService,
    private server: Service,
  ) { }

  ngOnInit() {
  }

  /**
   * 删除
   */
  _delete(){
    this.loading = true;
    this.removeTableService
    .confirmRemove('ids',this.server.baseUrl +"Service/Config/deleteMetaDataTemplate",'token',template.retrieval.token)
    .then(res => {
      if(res.result_code == '0000'){
        this.delete.emit();
      }
      this.loading = false;
      this.hintsService.messages(res.message,res.result_code);
      return;
    })
    .catch(err => {
      this.loading = false;
      this.hintsService.messages('error','error');
      return;
    });
  }

}
